package dht.mains;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;

import dht.data.DhtData;
import dht.data.Options;
import dht.node.Node;

public class ClientNodeTest {
	public static void main(String[] args) throws InterruptedException {

		Node mySelf = null;

		int dim = Options.dimensions;
		boolean init = false;
		//String adrrIp = "192.168.1.77";
		String adrrIp="192.168.1.20";

		try {
			mySelf = new Node(dim,init,adrrIp); 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		mySelf.start();
		
		while (mySelf.readyWork==false) {
			Thread.sleep(10);
		}
		
		System.out.println("coucou je suis arrivé la...");
		DhtData<Integer> d=new DhtData<Integer>(5);
		ArrayList<String> criteres=new ArrayList<String>();
		criteres.add(d.toString());criteres.add(d.toString());
		if (mySelf.PUT(criteres,d)==false) {
			System.out.println("oops...bug");
		}
		else { 
			System.out.println("J'ai envoyé : "+d+" sur la DHT");
		}
		System.out.println("cela devrait être "+d+" que je reçois et je reçois : "+mySelf.GET(criteres));
		
		
		System.out.println("fin du client");
		//ici devra etre un QUIT
		mySelf.StopWorking();
		return;
	}

}
